package com.example.sso.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.common.po.AuthClientAccount;
import com.example.common.service.ServiceImpl;
import com.example.sso.api.AuthClientAccountService;
import com.example.sso.mapper.AuthClientAccountMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class AuthClientAccountServiceImpl extends ServiceImpl<AuthClientAccount> implements AuthClientAccountService {

    @Override
    public BaseMapper<AuthClientAccount> getMapper() {
        return authClientAccountMapper;
    }

    @Autowired
    private AuthClientAccountMapper authClientAccountMapper;

    @Override
    public AuthClientAccount loadUserByUsername(String username) {
        QueryWrapper<AuthClientAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        return super.selectOne(wrapper);
    }

    @Override
    public AuthClientAccount getAccountInfoByOpenId(String openId) {
        QueryWrapper<AuthClientAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("open_id", openId);
        return super.selectOne(wrapper);
    }
}
